import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import eslintPlugin from "vite-plugin-eslint"
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
// import viteCompression from "vite-plugin-compression"
import path from "path"

export default defineConfig({
  plugins: [
    vue(),
    eslintPlugin({
      include: ["src/**/*.ts", "src/**/*.vue", "src/*.ts", "src/*.vue"]
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons")], // 指定缓存图标文件夹
      symbolId: "icon-[dir]-[name]" // symbolId格式
    })
    // viteCompression({
    //   verbose: true, // 默认即可
    //   disable: false, //开启压缩(不禁用)，默认即可
    //   deleteOriginFile: false, //删除源文件
    //   threshold: 10240, //压缩前最小文件大小
    //   algorithm: "gzip", //压缩算法
    //   ext: ".gz" //文件类型
    // })
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src")
    },
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"]
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/style/variables.scss";`
      }
    }
  },
  server: {
    proxy: {
      "/send_captcha": {
        target: "http://1.116.110.222:7001/api",
        changeOrigin: true,
        rewrite: path => path.replace(/^\/send_captcha/, "")
      }
    }
  }
})
